/**
 * @(#)com.framework.http.HttpTest
 *
 * Copyright (c) 2014-2018 一抹风光
 *
 * DESC:
 *
 */
package com.framework.http;

import com.alibaba.fastjson.JSON;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * @author fusf
 * @version 1.0  2017/7/27
 */
public class HttpTest {


    public static void main(String [] argc) {
        //发送 GET 请求
   /*     String s=HttpRequest.sendGet("https://oapi.dingtalk.com/gettoken", "corpid=dingac7d9ba33323788635c2f4657eb6378f&corpsecret=Atc8lJ7v65uYeRflAyxc8WlU1pMxXxnvVPE7q3o2Qm38Z8-wjN_EkxL57btFsBqo");
        System.out.println(s);
        AccessTokenResult accessTokenResult = JSON.parseObject(s, AccessTokenResult.class);
        System.out.println(accessTokenResult.getAccess_token());*/
      /*  TextMessageReq text = new TextMessageReq();
        text.setContent("欢迎来到钉钉8"+ UUID.randomUUID());

        MessageReq message = new MessageReq();
        //message.setToparty("");
        message.setTouser("manager3847");
        message.setAgentid("113836344");
        message.setMsgtype("text");
        message.setText(text);

        String jsonString = JSON.toJSONString(message);


        //发送 POST 请求
       String sr=HttpRequest.sentPost(" https://oapi.dingtalk.com/message/send?access_token=c3b9dc9bf56c38a3bed6eca7cb1ad2c7", jsonString);
        System.out.println(sr);
        //40014	不合法的access_token*/
    }

    @Test
    public void sendGet(){
        String s=HttpRequest.sendGet("https://oapi.dingtalk.com/gettoken", "corpid=dingac7d9ba33323788635c2f4657eb6378f&corpsecret=Atc8lJ7v65uYeRflAyxc8WlU1pMxXxnvVPE7q3o2Qm38Z8-wjN_EkxL57btFsBqo");
        System.out.println(s);
    }
    @Test
    public void sendPost(){
      Map<String,Object> map = new HashMap<String,Object>();
        map.put("j_username","hyunwang");
        map.put("j_password","123456");
        map.put("returnURL","www.baidu.com");
        String jsonString = JSON.toJSONString(map);


        //发送 POST 请求
        String sr=HttpRequest.sentPostByXml("http://localhost:9050/cpa/j_spring_security_check", jsonString);
        System.out.println(sr);
    }


}
